#include <iostream>
#include <vector>
#include <string>

using std::string;
using std::vector;


int explode(std::string str, std::string delimiter, std::vector<std::string> &store)
{
    int strlen = str.length();
    int dellen = delimiter.length();
    if (dellen==0) {
        return -1;//no change
    }
    int i=0; 
    int k=0;
    while( i<strlen ) {
        int j=0;
        while (i+j<strlen && j<dellen && str[i+j]==delimiter[j]) {
            j++;
        }
        if (j==dellen){ //found delimiter 
            store.push_back(str.substr(k, i-k));
            i+=dellen;
            k=i;
        } else {
            i++;
        }
    }
    store.push_back(str.substr(k, i-k));
    return store.size();
}
template<typename T>
void print(vector<T> &arr)
{
    size_t length = arr.size();
    for (size_t i = 0; i != length; ++i) {
        std::cout << arr.at(i) << '\n';
    }
}
int main()
{
    string test = "hai. test. test.testing";
    vector<string> ret;
    explode(test, ". ", ret);
    /*
    for (size_t i = 0; i != ret.size(); ++i) {
        std::cout << ret.at(i) << '\n';
    }
    */
    std::cout << ret.size() << std::endl;
    print(ret);
}
